/*
 *
 *  * Copyright (c) 2015, Oolong Studio, All Rights Reserved.
 *  *
 *  * Oolong Studio licenses this file to you under the Apache License,
 *  * Version 2.0 (the "License"). You may not use this file except in
 *  * compliance with the License. You may obtain a copy of the License at
 *  *
 *  *     http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 *  * CONDITIONS OF ANY KIND, either express or implied. See the License for
 *  * the specific language governing permissions and limitations under the
 *  * License.
 *  *
 *  * 版权声明2015,乌龙茶工作室
 *  *
 *
 */

package cn.nubia.admin.application;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * Created by justin on 15/6/25.
 */
public class APKUtils {

    static String  apkPath = APKUtils.class.getClassLoader().getResource("").getPath()+"baidushoujizhushouyuan.apk";


    public static String getAndroidManifestContent(String apkPath){
        InputStream inputStream;
        ZipFile zipFile;
        try {
            System.out.println(apkPath);
            zipFile = new ZipFile(new File(apkPath));
            ZipEntry zipEntry = zipFile.getEntry("AndroidManifest.xml");
            inputStream = zipFile.getInputStream(zipEntry);
            Document document =Jsoup.parse(inputStream, "UTF-8", "");
            return document.text();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }


    public static void main(String[] args) {
        System.out.println(getAndroidManifestContent(apkPath));
    }

}
